#ifndef __SUBSYSTEM_GRASS_BLOCK_BEHAVIOR_H__
#define __SUBSYSTEM_GRASS_BLOCK_BEHAVIOR_H__

#include <set>
#include <mutex>
#include "Engine/Point3.hpp"
#include "Subsystems/BlockBehaviors/SubsystemPollableBlockBehavior.hpp"
#include "GameLock.hpp"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    class SubsystemTimeOfDay;
    class SubsystemTerrain;
    class SubsystemGameInfo;

    // 草地方块，扩散行为
    class SubsystemGrassBlockBehavior : public SubsystemPollableBlockBehavior
    {
    protected:
        SubsystemTimeOfDay *m_timeOfDay;
        SubsystemTerrain *m_terrain;
        SubsystemGameInfo *m_gameInfo;

        std::map<Point3, int32_t> m_toUpdate;
        SpinLock m_toUpdateLock;

    public:
        SubsystemGrassBlockBehavior();
        bool killsGrassIfOnTopOfIt(int32_t value);

        virtual void onPoll(int32_t value, int32_t x, int32_t y, int32_t z) override;
        virtual void onNeighborBlockChanged(int32_t x, int32_t y, int32_t z, int32_t neighborX, int32_t neighborY, int32_t neighborZ) override;
        virtual void onExplosion(int32_t value, int32_t x, int32_t y, int32_t z, float damage) override;

        virtual void update(float dt) override;
        virtual void load(const nlohmann::json& json) override;

        virtual const std::string& getName() const override;
        virtual SubUpdateType getUpdateType() override;
    };
    
}

#endif
